<template>
	<view class="container">
		<!-- 头部导航栏 -->
		<view class="bac"></view>

		<!-- 车辆列表 -->
		<view class="vehicle-list">
			<view 
				class="vehicle-item" 
				v-for="(item, index) in vehicleList" 
				:key="index"
				:class="{ 'vehicle-item-selected': item.selected }"
				@click="selectVehicle(index)"
			>
				<view class="vehicle-image-wrapper">
					<image class="vehicle-image" :src="item.image" mode="aspectFill"></image>
				</view>
				<view class="vehicle-info">
					<view class="vehicle-model">车型:{{ item.model }}</view>
					<view class="vehicle-plate">车牌:{{ item.plate }}</view>
				</view>
				<view class="vehicle-selector">
					<view class="selector-icon" :class="{ 'selector-selected': item.selected }">
						<text v-if="item.selected" class="checkmark">✓</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 底部添加按钮 -->
		<view class="bottom-action">
			<button class="add-vehicle-btn" @click="addVehicle">
				<text class="add-icon">+</text>
				<text class="add-text">添加车辆</text>
			</button>
		</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue'

	const vehicleList = ref([
		{
			model: '奔驰-GR',
			plate: '豫M35468',
			image:'/static/Maintenance/car.jpg',
			selected: true
		},
		{
			model: '奔驰-GR',
			plate: '豫M35468',
			image: '/static/Maintenance/car.jpg',
			selected: false
		}
	])

	const selectVehicle = (index) => {
		// 单选逻辑：先取消所有选中，再选中当前项
		vehicleList.value.forEach((item, i) => {
			item.selected = i === index
		})
	}

	const goBack = () => {
		uni.navigateBack()
	}

	const addVehicle = () => {
		uni.showToast({
			title: '添加车辆功能',
			icon: 'none'
		})
		// 可以在这里添加跳转到添加车辆页面的逻辑
	}
</script>

<style scoped>
	.container {
		width: 100%;
		min-height: 100vh;
		background-color: #f5f5f5;
	}
	
	.bac {
		background-color: #2b85e4;
		height: 200rpx;
	}

	/* 头部导航栏 */
	.header {
		width: 100%;
		height: 88rpx;
		background-color: #2b85e4;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 30rpx;
		box-sizing: border-box;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 100;
	}

	.header-left {
		width: 60rpx;
		height: 60rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.back-icon {
		font-size: 40rpx;
		color: #fff;
		font-weight: bold;
	}

	.header-title {
		font-size: 36rpx;
		font-weight: bold;
		color: #fff;
	}

	.header-right {
		display: flex;
		align-items: center;
		gap: 30rpx;
		width: 60rpx;
		justify-content: flex-end;
	}

	.menu-icon {
		font-size: 40rpx;
		color: #fff;
		line-height: 1;
	}

	.location-icon {
		font-size: 36rpx;
		color: #fff;
	}

	/* 车辆列表 */
	.vehicle-list {
		margin-top: -150rpx;
		padding: 30rpx;
		padding-bottom: 150rpx;
	}

	.vehicle-item {
		background-color: #fff;
		border-radius: 20rpx;
		padding: 30rpx;
		margin-bottom: 20rpx;
		display: flex;
		align-items: center;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
		transition: all 0.3s;
	}

	.vehicle-item-selected {
		box-shadow: 0 4rpx 20rpx rgba(43, 133, 228, 0.2);
		border: 2rpx solid #2b85e4;
	}

	.vehicle-image-wrapper {
		width: 120rpx;
		height: 120rpx;
		border-radius: 50%;
		overflow: hidden;
		margin-right: 30rpx;
		flex-shrink: 0;
		background-color: #f5f5f5;
	}

	.vehicle-image {
		width: 100%;
		height: 100%;
	}

	.vehicle-info {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.vehicle-model {
		font-size: 32rpx;
		font-weight: bold;
		color: #333;
		margin-bottom: 10rpx;
	}

	.vehicle-plate {
		font-size: 28rpx;
		color: #333;
	}

	.vehicle-selector {
		width: 60rpx;
		height: 60rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-shrink: 0;
	}

	.selector-icon {
		width: 50rpx;
		height: 50rpx;
		border-radius: 50%;
		border: 2rpx solid #d9d9d9;
		background-color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
		transition: all 0.3s;
	}

	.selector-selected {
		background-color: #ff8c00;
		border-color: #ff8c00;
	}

	.checkmark {
		font-size: 32rpx;
		color: #fff;
		font-weight: bold;
		line-height: 1;
	}

	/* 底部添加按钮 */
	.bottom-action {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		padding: 30rpx;
		background-color: #fff;
		box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
	}

	.add-vehicle-btn {
		width: 100%;
		height: 88rpx;
		background-color: #2b85e4;
		border-radius: 44rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		gap: 15rpx;
		border: none;
	}

	.add-icon {
		font-size: 40rpx;
		color: #fff;
		font-weight: bold;
		line-height: 1;
	}

	.add-text {
		font-size: 32rpx;
		color: #fff;
		font-weight: 500;
	}
</style>